package com.etung.iot.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.etung.iot.demo.boxConfig.Box;
import com.etung.iot.demo.modles.UserEntity;
import com.etung.iot.demo.services.UserService;
import com.etung.iot.demo.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
@Api(tags = "用户信息接口")
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation(value = "注册")
    @PostMapping("/register")
    public Result<?> registerUser(@RequestBody UserEntity user ){
        userService.register(user);
        return Result.OK();
    }

    @PostMapping("/login")
    @ApiOperation(value = "登录")
    public Result<?> login(@RequestBody UserEntity user){
        String token = userService.login(user);
        JSONObject res = new JSONObject();
        res.put("token",token);
        return Result.OK(res);
    }


}
